//
//  BaseViewModel.m
//  ZhaoCaiMao
//
//  Created by 谢英泽 on 2017/3/17.
//  Copyright © 2017年 谢英泽. All rights reserved.
//

#import "BaseViewModel.h"
#import "DDAlertView.h"


@implementation BaseViewModel

@synthesize request = _request;

+ (instancetype)viewModel {
    return [[BaseViewModel alloc] init];
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self initialize];
    }
    return self;
}

- (void)initialize {}

#pragma mark - interface
/**
 错误信息弹框
 @param msg 错误信息
 */
- (void)showAlertViewWithMessage:(NSString *)msg {
    DDAlertView *alert = [[DDAlertView alloc] initWithTitle:@"温馨提示" content:msg ensureButtonTitle:nil cancelButtonTitle:@"我都知道了"];
    [alert show];
}

/**
 该方法为通用方法，数据不需要转换
 */
- (void)getBaseDataFromNetworkWithMethod:(NSString *)method param:(NSArray *)params result:(ViewModelResult)result {
    NetworkParam *param = [NetworkParam new];
    param.methodName = method;
    param.paramArr = [NSMutableArray arrayWithArray:params];
    [[NetworkCenter shareInstance] networkRequestWithNetworkParam:param completed:^(BOOL isSucess, id response) {
        if (isSucess) {
            result(YES,response);
        }else{
            result(NO,response);
        }
    }];
}

#pragma mark - Setter && Getter

- (void)setUpdateType:(kModelListUpdateStyle)updateType {
    _updateType = updateType;
}

- (NSMutableArray *)viewModelList {
    if (!_viewModelList) {
        _viewModelList = [NSMutableArray array];
    }
    return _viewModelList;
}

- (NetworkCenter *)request {
    if (!_request) {
        _request = [NetworkCenter shareInstance];
    }
    return _request;
}

@end
